<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>确认返库教具信息</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-table
            ref="multipleTable"
            :data="teachList"
            :stripe="tableStripe"
            :border="tableBorder"
            :height="tableHeight"
            tooltip-effect="dark"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c">
          <el-table-column
              label="教具名称"
              align="center">
            <template slot-scope="scope">
              {{scope.row.tools.name}}
            </template>
          </el-table-column>
          <el-table-column
              prop="num"
              label="教具类目"
              align="center">
            <template slot-scope="scope">
              {{scope.row.tools.cate?scope.row.tools.cate.name:'未知'}}
            </template>
          </el-table-column>
          <el-table-column
              prop="num"
              label="班级数量"
              width="120"
              align="center">
          </el-table-column>
          <el-table-column
              label="返库数量"
              align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.backnumber" size="small" placeholder="返库数量"></el-input>
            </template>
          </el-table-column>
          <el-table-column
              prop="num"
              label="操作"
              align="center">
            <template slot-scope="scope">
              <el-button size="small" @click="backTeach(scope.$index,scope.row)" type="danger" plain>删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">继续添加返库教具</el-button>
        <el-button @click="saveOptionFn" size="small" >确认并提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {tools_return_add} from '@/api/admin/teaching'

export default {
  props: ['visible','teachList'], // commoent 学生点评 collection 学生采集
  components: {
  },
  data() {
    return {
      dialogVisible: false,
      tableStripe: true, // 是否斑马栏
      tableBorder: true, // 单元格右边边框
      tableHeight: 0
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if(this.visible){
        let n =this;
        this.$nextTick(()=>{
          let height= n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          this.tableHeight = height - (51+40+51)
          console.log('height:', height)
        })
      }
    },
  },
  created() {

  },
  methods: {
    saveOptionFn(){
      let list_ = JSON.parse(JSON.stringify(this.teachList))
      let query_ = []
      let state = true
      for(let item of list_){
        if(Number(item.num)<Number(item.backnumber)){
          state = false
        }
        query_.push({
          id:item.tools_id,
          number: item.backnumber
        })
      }
      if(!state){
        this.$message.error('返库数量不能大于班级现有数量')
        return
      }
      console.log('query_',query_)
      // let state_ = 1
      // if(state_){
      //   return
      // }
      tools_return_add({data: JSON.stringify(query_)}).then(res=>{
        console.log('提交：', res)
        if(!res.data){
          this.$message.success(res.msg)
          this.$emit('closeList', {type: 2})
        }else{
          this.$message.error(res.msg)
        }
      })
    },
    backTeach(index, row){
      this.$emit('closeList',{index: index,id:row.id,type: 1})
    },
    refreshFn(){
      this.editForm.section_id = '';
      this.editForm.class_id = '';
      this.editForm.cate_id = ''
      this.editForm.name = ''
      this.page.pageindex = 1;
      this.page.total = 0;
      this.arryList = [];
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option){
      return JSON.parse(JSON.stringify(option))
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 75%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding:20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}
.hearder-search{
  display: flex;
  align-items: center;
}
</style>


